package com.ampaiva.organizescreen.activity;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Shader;

import com.ampaiva.organizescreen.model.Node;

public class NodeDrawer {
	Paint paint = new Paint();

	public void draw(Canvas canvas, Node node) {
		int color = node.isTouched() ? Color.RED : Color.GREEN; // (node.isInRightPosition()
		                                                        // ? Color.GREEN
		                                                        // :
		                                                        // Color.LTGRAY);
		paint.setShader(new LinearGradient(node.getRegion().getBounds().left, node.getRegion().getBounds().top, node.getRegion().getBounds().left, node
		        .getRegion().getBounds().bottom, color, Color.WHITE, Shader.TileMode.CLAMP));
		canvas.drawRect(node.getRegion().getBounds(), paint);

		Rect bounds = new Rect();
		String text = String.valueOf(node.getId());
		paint.setTextSize((node.getRegion().getBounds().right - node.getRegion().getBounds().left) / 2);
		paint.getTextBounds(text.toString(), 0, text.length(), bounds);
		int x = node.getRegion().getBounds().left + bounds.width() / 2;
		int y = node.getRegion().getBounds().top + bounds.height();
		paint.setShader(null);
		paint.setColor(Color.YELLOW);
		canvas.drawText(text.toString(), x, y, paint);
	}

}
